
import React from 'react'
import ReactDOM from 'react-dom'
import error from 'assets/images/error.png'
import succeed from 'assets/images/succeed.png'
import Hint from 'assets/images/hint.png'
import {Exit} from 'action/operation'

export  class Aletts extends React.Component {

	constructor(props){
		super(props)
		this.state={
			show:this.props.data,
		}
	}
	
	Cunter(){	
		setTimeout(()=>{
			const Element=document.querySelector('.Messages');
			Element.remove() },3500);
	}
	
	Close(){
		Exit(sessionStorage.admin_token);
	}
	
	abandon(){
		document.querySelector('.exitMessage').remove()
	}
	
	componentDidMount(){

		if(this.state.show.code != null)
			this.Cunter();	
	}
	
	componentWillReceiveProps(nextProps){
		if(this.state.show !== nextProps.data){
			this.setState({show:nextProps.data});
		}
	}

	render(){
			if(this.state.show.code != null){
				
				return(
					<div className="Alert1" >
						<img src={this.state.show.code != 200 ? error:succeed } />
						<span>{this.state.show.message}</span>
					</div>
				)
				
			}else if(this.state.show === 'Exit'){
				
				return(
					<div className="exitMessage">
						<h5>
							<img src={Hint} />确认退出账号?</h5>
							<span onClick={this.Close.bind(this)}>退出</span>
							<span onClick={this.abandon.bind(this)}>取消</span>
					</div>
				)
		}
	}
}
